package com.cb.web.wasf.tag;

import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import javax.servlet.jsp.tagext.TryCatchFinally;

/**
 * @author CBO
 */
public class BlocTag extends TagSupport implements TryCatchFinally {

    private String title;
    private String width;

    public void setTitle(String title) {
        this.title = title;
    }

    public void setWidth(String width) {
        this.width = width;
    }

    @Override
    public int doStartTag() throws JspException {
        StringBuilder sb = new StringBuilder();
        sb.append("<div class=\"ui-dialog ui-widget ui-widget-content ui-corner-all\"");
        if (id != null) {
            sb.append(" id=\"").append(id).append("\"");
        }
        sb.append(" style=\"outline-width: 0px; outline-style: initial; outline-color: initial; display: block;");
        if (width != null) {
            sb.append(" width: ").append(width).append(";");
        }
        
        sb.append("\">");
        if (title != null) {
            sb.append("<div class=\"ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix\">");
            sb.append("<span class=\"ui-dialog-title\">");
            sb.append(title);
            sb.append("</span>");
            sb.append("</div>");
        }
        sb.append("<div class=\"ui-widget-content ui-dialog-content\">");
        
        try {
            pageContext.getOut().print(sb.toString());
        } catch (IOException ioe) {
            throw new JspException(ioe);
        }
        return EVAL_BODY_INCLUDE;
    }

    @Override
    public int doEndTag() throws JspException {
        StringBuilder sb = new StringBuilder();
        sb.append("</div></div>");
        try {
            pageContext.getOut().print(sb.toString());
        } catch (IOException ioe) {
            throw new JspException(ioe);
        }
        return EVAL_PAGE;
    }

    @Override
    public void doCatch(Throwable throwable) throws Throwable {
        throw throwable;
    }

    @Override
    public void doFinally() {
        id = null;
        title = null;
        width = null;
    }

}
